<?php
namespace App\Http\Controllers;

use App\Models\Bulletin;
use App\Http\C5\C5ResponseFactory;
use App\Models\Province;
use App\Utils\ResourceUtils;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use p5\objects\SqlMaker;
use p5\objects\TimeUtils;

class WxBulletinController extends BulletinController
{

    /**
     * 获取最近的 n 条资讯记录
     * @return \App\Http\C5\C5Response
     */
    public function recents()
    {
        $oid = $this->currentOrganizationId();
        $now = TimeUtils::current_date();
        $limits = SqlMaker::make_limits($this->request->all());
        $sql = "
            select bulletin_id,type_id,subject,brief,from_time,image_save_name
            from bulletin a
            where status_id=2
            and organization_id=$oid
            and from_time <= '$now'
            and to_time >= '$now'
            $limits
            order by from_time desc
            limit 0,2000
        ";
        Log::debug($sql);
        $list = DB::select($sql);
        $list = json_decode(json_encode($list), true);
        ResourceUtils::toInternets($list, "image_save_name");
        return C5ResponseFactory::newSuccessInstance($list);
    }


}

